package io.adrainty.algorithm.mars;

/**
 * 比赛配对问题
 * @link <a href="https://www.marscode.cn/practice/364l85wv6oo6lq?problem_id=7427688461827653676">...</a>
 * @author AdRainty
 * @version V1.0.0
 * @since 2024/11/30 下午5:03
 */
public class Solution020 {

    private Solution020() {}

    public static int solution(int n) {
        // write code here
        if (n <= 1) return 0;
        if (n == 2) return 1;
        if (n % 2 == 0) return (n / 2) + solution(n / 2);
        return ((n - 1) / 2) + solution((n - 1) / 2 + 1);
    }

    public static void main(String[] args) {
        System.out.println(solution(7) == 6);
        System.out.println(solution(14) == 13);
        System.out.println(solution(1) == 0);
    }

}
